/*
 * 1742. Self Dividing Numbers
 * 一个数字整除数是指一个可以被其中包含的每个数字整除的数.
 * 举个例子, 128是一个数字整除数, 因为 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.
 * 并且, 数字整除数不允许包含数字 0.
 * 给出数字取值的上下限, 输出一个包含所有数字整除数的列表, 包括边界.
 * https://www.lintcode.com/problem/self-dividing-numbers/description
 * 
 * 样例
 * 给出 left = 1, right = 22, 返回 [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
 * 
 * 2018.06.12 @jeyming
 */
package self_dividing_numbers_1742;

import java.util.ArrayList;
import java.util.List;

public class Self_dividing_numbers_1742 {
    /**
     * @param lower: Integer : lower bound
     * @param upper: Integer : upper bound
     * @return: a list of every possible Digit Divide Numbers
     */
    public static List<Integer> digitDivideNums(int lower, int upper) {
        // write your code here
    	List<Integer> list = new ArrayList<Integer>();
    	for(int i = lower; i <= upper; ++i) {
    		int num = i;
    		boolean judge = true;
    		while(num > 0) {
    			int tmp = num % 10;
    			if((tmp == 0) || (i % tmp != 0)) {
    				judge = false;
    				break;
    			}
    			num /= 10;
    		}
    		if(judge)
    			list.add(i);
    	}
    	for(int i = 0; i < list.size(); ++i) {
    		System.out.println(list.get(i));
    	}
    	return list;
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		digitDivideNums(2147483000,2147483647);

	}

}
